<?php
/**************************************************************************************************
|
| AudioShare - Audio Sharing Script
| http://www.audiosharescript.com
| webmaster@audiosharescript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.audiosharescript.com/eula.html and to be bound by it.
|
| Copyright (c) 2010 AudioShareScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

$getfilter = htmlentities(strip_tags($_REQUEST[filter]));
$filter = escape($getfilter);
$showmax = $config['max_syndicate_results'];

if ($filter =="0")
{
	$query = "SELECT * from audios where public='1' AND active='1' order by time_added desc limit $showmax";
	$showtitle = "$lang[826]";
	$link   = $config['baseurl']."/syndicate/audios/0/$lang[174]"; 
}
elseif ($filter =="1")
{
	$query = "SELECT * from audios where public='1' AND active='1' order by viewcount desc limit $showmax";
	$showtitle = "$lang[827]";
	$link   = $config['baseurl']."/syndicate/audios/1/$lang[178]";
}
elseif ($filter =="2")
{
	$query = "SELECT * from audios where public='1' AND active='1' order by rating desc limit $showmax";
	$showtitle = "$lang[828]";
	$link   = $config['baseurl']."/syndicate/audios/2/$lang[179]";
}
elseif ($filter =="3")
{
	$query = "SELECT * from audios where public='1' AND active='1' order by commentcount desc limit $showmax";
	$showtitle = "$lang[829]";
	$link   = $config['baseurl']."/syndicate/audios/3/$lang[180]";
}
elseif ($filter =="4")
{
	$query = "SELECT * from audios where public='1' AND active='1' order by favoritecount desc limit $showmax";
	$showtitle = "$lang[830]";
	$link   = $config['baseurl']."/syndicate/audios/4/$lang[182]";
}
elseif ($filter =="6")
{
	$query = "SELECT * from audios where public='1' AND active='1' AND featured='1' order by time_added desc limit $showmax";
	$showtitle = "$lang[803]";
	$link   = $config['baseurl']."/syndicate/audios/6/$lang[53]";
}


header("Content-Type: text/xml"); 
header("Expires: 0"); 
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; 
print "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\">\n"; 
print "<channel>\n"; 
print "<title>".$showtitle." - ".stripslashes($config['site_name'])."</title>\n"; 
print "<link>$link</link>\n"; 
print "<description>".$showtitle."</description>\n"; 
$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME); 
@mysql_query("SET NAMES 'UTF8'");
@mysql_query("SET NAMES 'UTF8'");
$result = mysql_query($query) or die ('Query Error: ' . mysql_error()); 
while ($results = mysql_fetch_array($result)) 
{ 
  $thumbnail       = $config['athumburl']."/".$results['AUDIOID']."-1".$results['ext']; 
  $audio       = $config['baseurl']."/audios/".$results['AUDIOID']."/".seo_clean_titles_sendmail($results['title']); 
  $description = str_replace ("&amp","",htmlspecialchars(stripslashes($results['description']))); 
  
  $query="SELECT username FROM members WHERE USERID='".mysql_real_escape_string($results[USERID])."'";
  $executequery=$conn->execute($query);
  $getusername = $executequery->fields[username];
		
	print "<item>\n"; 
	print "  <title><![CDATA[".$results['title']."]]></title>\n";
	print "  <link>".$audio."</link>\n"; 
	print "  <description>\n"; 
	print "    <![CDATA["; 
	print "<img src=\"$thumbnail\" align=\"right\" border=\"0\" width=\"170\" height=\"120\" vspace=\"5\" hspace=\"5\"/>".$description."<br><br>$lang[672]: <a href=\"$config[baseurl]/$getusername\">$getusername</a>"; 
  	
	print "<br />$lang[11] ";
	$query="SELECT date_added FROM audios WHERE AUDIOID='".mysql_real_escape_string($results['AUDIOID'])."'";
	$executequery=$conn->execute($query);
	$list=explode('-',$executequery->fields[date_added]);
	print_r($list[2]);print_r('-');
	print_r($list[1]);print_r('-');
	print_r($list[0]);
	
	$query = "select name from categories_audios WHERE CATID='".mysql_real_escape_string($results['categories'])."' limit 1"; 
	$executequery = $conn->execute($query);
	$category = $executequery->fields[name];
	
	print "<br>$lang[218]: $category<br/>$lang[235]: "; 
	$gettags = strtok($results[tags], " "); 
  	while ($gettags !== false) 
  	{ 
    	print "<a href=\"$config[baseurl]/search/audios/a/0/".$gettags."\">".$gettags."</a> "; 
    	$gettags = strtok(" "); 
  	} 
	
	print "<br>$lang[60]: $results[viewcount] | $lang[63]: $results[commentcount]";
	
	
	print "<br/><br/><br /><hr>"; 
	print "    ]]>\n"; 
	print "  </description>\n"; 
	print "  <author>".$getusername."</author>\n"; 
	print "</item>\n"; 
} 
mysql_close(); 
print "</channel>\n"; 
print "</rss>"; 
?> 